<?php
/**
 * 管理后台-权限管理控制器-RCenter
 * 用于控制权限管理页的显示、权限条目的增删改
 * @author Pony
 */
class right extends spController{
	function __construct(){
		if($_SESSION['ucid'] != RC_ADMIN){$this->error('您不是RCenter管理员',spUrl('main','login'));}
		parent::__construct();
	}
	
	function index(){
		$lib = spClass('lib_right');
		$this -> group_options = $lib -> exGroup();
		$this -> rightlist = $lib -> getRights();
		$this -> rightlist = $lib -> exGroupId($this -> rightlist);
		$this -> tpl_img = TPL_IMG;
		$this -> display('admin_right.htm');
	}
	
	function add(){
		$lib = spClass('lib_right');
		$r = $lib -> addRight($this -> spArgs('rightsnum'),
							  $this -> spArgs('description',' '),
							  $this -> spArgs('groupid'),
							  $this -> spArgs('allow'),
							  $this -> spArgs('begin'),
							  $this -> spArgs('end'));
		if($r > 0) $this->success('成功创建一条权限',spUrl('right'));
		else $this -> error('创建权限失败',spUrl('right'));
	}
	
	function delete(){
		$lib = spClass('lib_right');
		$deletes_wait = $this->spArgs('delete');
		while ($foo = each($deletes_wait)){
			$lib -> deleteRight($foo['value']);
		}
		$this->success('已从RCenter中删除选定权限',spUrl('right'));
	}
	
	function edit_page(){
		$lib = spClass('lib_right');
		$this -> rightinfo = $lib -> getRights($this->spArgs('rightid'));
		$this -> timebegin = empty($this -> rightinfo['begin']) ? 0 : date('YmdHis',$this -> rightinfo['begin']);
		$this -> timeend = empty($this -> rightinfo['end']) ? 0 : date('YmdHis',$this -> rightinfo['end']);
		$this -> group_options = $lib -> exGroup();
		$this -> tpl_img = TPL_IMG;
		$this -> display('admin_right_edit.htm');
	}
	
	function edit(){
		$lib = spClass('lib_right');
		$r = $lib -> editRight($this -> spArgs('rightid'),
							  $this -> spArgs('rightsnum'),
							  $this -> spArgs('description',' '),
							  $this -> spArgs('groupid'),
							  $this -> spArgs('allow'),
							  $this -> spArgs('begin'),
							  $this -> spArgs('end'));
		if($r > 0) $this->success('成功修改一条权限',spUrl('right'));
		else $this -> error('修改权限失败或无变化',spUrl('right'));
	}
}